package com.sky.controller.admin;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@Api(tags = "菜品相关接口")
@RequestMapping("/admin/dish")
@Log4j2

public class DishController {

    @Autowired
    DishService dishService;

    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dishDTO){
        return dishService.addDish(dishDTO);
    }


    @GetMapping("/page")
    @ApiOperation("菜品分页")
    public Result queryPage(DishPageQueryDTO dishPageQueryDTO){
        PageResult pageResult = dishService.queryPage(dishPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/list")
    @ApiOperation("根据分类id查询菜品")
    public Result list(Long categoryId){
        List<Dish> categorys = dishService.findDishCateGoryById(categoryId);
        return Result.success(categorys);
    }


    @PostMapping("/status/{status}")
    @ApiOperation("菜品起售、禁售")
    public Result statusDish(@PathVariable("status") Integer status, Long id){
        dishService.statusDish(status, id);
        return Result.success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据Id查找菜名")
    public Result queryDishById(@PathVariable("id") Long id){
        DishVO dishVO = dishService.queryDishById(id);
        return Result.success(dishVO);
    }

    @PutMapping
    @ApiOperation("修改菜品")
    public Result putDish(@RequestBody DishDTO dishDTO){
        dishService.putDish(dishDTO);
        return Result.success();
    }
    @DeleteMapping
    @ApiOperation("删除菜品名单")
    public Result delDish(@RequestParam("ids") List<Long> ids){
        String result = dishService.delDishByIds(ids);
        return Result.success(result,null);
    }
}
